package com.zkdcloud.aspectInterceptor.advice;

import com.xdja.interceptor.advice.HttpAdvice;
import com.xdja.interceptor.exception.InvokeException;
import org.jfaster.mango.plugin.page.Page;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author zk123
 * @version 2018/5/22
 */
@Component
public class MobilePageAdvice implements HttpAdvice{
    @Override
    public void doAdvice(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Map<String, Object> map) throws InvokeException {
        String pageNo = httpServletRequest.getParameter("page");
        String pageSize = httpServletRequest.getParameter("size");

        Page page = (Page) map.get("page");
        if(page != null){
            Integer pageNum = Integer.parseInt(pageNo);
            page.setPageNum(pageNum <=0 ? 1 : pageNum);
            page.setPageSize(Integer.parseInt(pageSize));
        }
    }
}
